package com.example.demo.java8.stream;

import java.util.Arrays;
import java.util.List;


import static java.util.stream.Collectors.toList;

/**
 * Description: <br/>
 *
 * @author liulonglong
 * @taskId <br/>
 * @Date 2019/11/21 10:48
 * @Version 1.0
 */
public class StreamTest3 {

    public static void main(String[] args) {
        // 获取每个元素的name属性放入一个新流中，然后把这个流转为List类型。
        List<String> words = Arrays.asList("AA", "B", "CCC", "DDDDDD");

        //    List<Person> names = peoples.stream().map(Person::getName).collect(toList());
        List<Integer> wordLengths = words.stream().map(String::length).collect(toList());
        wordLengths.forEach(System.out::println);

        List<String> words2 = Arrays.asList("Hello", "world");
        List<String[]> list = words2.stream().map(word -> word.split("")).collect(toList());
        list.forEach(item -> {
            for (String s : item) {
                System.out.print(s + ",");
            }
            System.out.println();
        });

        List<String> strings = words2.stream().map(word -> word.split("")).flatMap(Arrays::stream).collect(toList());
        strings.stream().forEach(System.out::print);
    }
}
